const { getAllGroupList,getGroupListByBranchId,getAllBranchList } = require("../model/teams");
const { responsSuccess, responsError } = require("../utils/responseUtil");
const {validateParams} = require("../utils/validateReqParam");
module.exports.getAllTeamListController=async function(request, response){
    getAllGroupList().then(teams=>{
        responsSuccess(response, {teams})
    }).catch(err => {
        console.log('getAllTeamListController --> err', err)
        responsError(response, err)
    })
}


module.exports.getAllBranchListController=async function(request, response){
    getAllBranchList().then(teams=>{
        responsSuccess(response, {teams})
    }).catch(err => {
        console.log('getAllBranchListController --> err', err)
        responsError(response, err)
    })

}

module.exports.getGroupListByBranchIdController=async function(request, response){
    validateParams(request.params, { //url参数即使传递数字，接收到也是string类型
        'branchId': { required: true,type: 'string', default:null,strReg:/^\d+$/ }
    }).then(reqData =>{
        getGroupListByBranchId(reqData['branchId']).then(teams=>{
            responsSuccess(response,{teams})
        }).catch(err=>{
            console.log('getGroupListByBranchIdController --> err',err)
            throw err
        })
    }).catch(err=>{
        console.log('getGroupListByBranchIdController --> err',err)
        responsError(response,err)
    })

}
